package com.kai.service.user.controller;

import com.kai.service.data.Result;
import com.kai.service.data.request.user.UpdateUserColumn;
import com.kai.service.data.request.user.UserColumnRequest;
import com.kai.service.data.response.user.UserColumnResponse;
import com.kai.service.user.service.IUserColumnService;
import com.kai.service.util.ResultResponseUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/user")
@Tag(name = "用户专栏")
public class UserColumnController {

    @Autowired
    private IUserColumnService userColumnService;

    /**
     * 新增用户专栏
     *
     * @param userColumnRequest
     * @return
     */
    @PostMapping("/column")
    @Operation(summary = "新增用户专栏")
    public Result<Boolean> createUserColumn(@Valid @RequestBody UserColumnRequest userColumnRequest){
        return ResultResponseUtil.success(userColumnService.createUserColumn(userColumnRequest));
    }

    /**
     * 查询用户专栏列表
     *
     * @param userId
     * @return
     */
    @GetMapping("/column/{userId}")
    @Operation(summary = "查询用户专栏列表")
    public Result<List<UserColumnResponse>> userColumn(@PathVariable("userId") Long userId){
        return ResultResponseUtil.success(userColumnService.userColumn(userId));
    }

    /**
     * 修改用户专栏名称
     *
     * @param columnId
     * @param updateUserColumn
     * @return
     */
    @PutMapping("/column/{columnId}")
    @Operation(summary = "修改用户专栏名称")
    public Result<Boolean> updateColumn(@PathVariable("columnId") Integer columnId, @Valid @RequestBody UpdateUserColumn updateUserColumn){
        return ResultResponseUtil.success(userColumnService.updateColumn(columnId, updateUserColumn));
    }

    /**
     * 删除用户专栏
     *
     * @param columnId
     * @return
     */
    @DeleteMapping("/column/{columnId}")
    @Operation(summary = "删除用户专栏")
    public Result<Boolean> deleteColumn(@PathVariable("columnId") Integer columnId){
        return ResultResponseUtil.success(userColumnService.deleteColumn(columnId));
    }
}
